{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="">上传二维码</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/qrcode/save')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">批量上传</label>
                        <div class="layui-input-block">
                            <input type="file" name="qrcode[]" class="layui-upload-file" id="qrcode"  multiple="multiple">
                            <div class="qrcode_img"></div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item layui-show">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 15px;"><input type="checkbox" class="check-all"></th>
                        <th>二维码</th>
                        <th>是否开启</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach name="info" item="v"}
                    <tr>
                        <td><input type="checkbox" name="ids[]" value=""></td>
                        <td>
                            {foreach name="v['images']" item="vo"}
                            <img width="200" src="{$vo.url}" />
                            {/foreach}
                        </td>
                        <td>
                            <form class="layui-form" action="">
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="checkbox" lay-filter="filter" value="{$v.id}" lay-text="开启|关闭" lay-skin="switch" {eq name="$v['is_open']" value="1"}checked{/eq}>
                                    </div>
                                </div>
                            </form>
                        </td>
                        <td>
                            <a href="" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    layui.use('form', function(){
        var form = layui.form();
        form.on('switch(filter)', function(data){
            $.ajax({
                url:'{:url("admin/qrcode/openAndClose")}',
                type:'POST',
                data:{type:data.elem.checked,contro_id:data.value},
                success:function(res){
                    if(res.status == 2){
                        layer.msg(res.msg); 
                        data.elem.checked = false;
                        form.render(); //更新全部
                        console.log(data.elem.checked);
                    }else{
                        layer.msg(res.msg); 
                    }
                    location.reload();
                }
            });
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象

        });  
        //各种基于事件的操作，下面会有进一步介绍
    });
</script>
{/block}